var hp_gba = '255,99,132';
var hw_gba = '179,181,198';
var lx_gba = '75,192,192';

var test = {};

/*
test['test_io_summary_3'] = {
    'labels': ['总分', '评分'];
    'title' : '项目总分和评分',
}
*/


test['test_io_1'] = {
    'labels': ['512B', '4KB', '16KB', '1MB', '随机'],
    'title' : '存储读写 - 操作/秒 （IOPS）',
};

test['test_io_2'] = {
    'labels': ['512B', '4KB', '16KB', '1MB', '随机'],
    'title' : '存储读写 - 评价存取时间 (ms)',
};

test['test_io_3'] = {
    'labels': ['512B', '4KB', '16KB', '1MB', '随机'],
    'title' : '存储读写 - 最大存取时间 (ms)',
};

test['test_io_4'] = {
    'labels': ['512B', '4KB', '16KB', '1MB', '随机'],
    'title' : '存储读写 - 平均存取时间 (ms)',
};

test['test_io_5'] = {
    'labels': ['内存', 'L1缓存', 'L2缓存', 'L3缓存'],
    'title' : '内存和CPU缓存测试 - 读',
};

test['test_io_6'] = {
    'labels': ['内存', 'L1缓存', 'L2缓存', 'L3缓存'],
    'title' : '内存和CPU缓存测试 - 写',
};

test['test_io_7'] = {
    'labels': ['内存', 'L1缓存', 'L2缓存', 'L3缓存'],
    'title' : '内存和CPU缓存测试 - 复制',
};

test['test_io_8'] = {
    'labels': ['内存', 'L1缓存', 'L2缓存', 'L3缓存'],
    'title' : '内存和CPU缓存测试 - 延迟',
};

test['test_io_9'] = {
    'labels': ['wow', 'bf3', 'apl', 'ahp', 'ai', 'aae', 'ail', 'mw', 'me', 'mpp'],
    'title' : '常见应用存取测试 - (s)',
};

test['test_io_10'] = {
    'labels': ['评分', '完成时间(s)'],
    'title' : '常见应用测试综合',
};

test['test_io_11'] = {
    'labels': ['word', 'excel', 'powerpoint'],
    'title' : '办公软件性能测试',
};

test['test_io_12'] = {
    'labels': ['评分', '完成时间(s)'],
    'title' : '办公软件性能综合',
};

test['test_io_13'] = {
    'labels': ['随机1', '随机2', '随机3', '随机4', '1G'],
    'title' : '网络传输测试(MB/s)',
};

// IO
/*
test['test_io_14'] = {
    'labels': ['读(MB/s)', '写(MB/s)'],
    'title' : '4K 读写(MB/s)',
};

test['test_io_15'] = {
    'labels': ['读(MB/s)', '写(MB/s)'],
    'title' : '持续读写(MB/s)',
};
*/

// IORW
test['test_iorw_1'] = {
    'labels': ['READ 5s', 'WRITE 5s'],
    'title' : 'SEQ长间隔读写(MB/s)',
};

test['test_iorw_2'] = {
    'labels': ['READ 5s', 'WRITE 5s'],
    'title' : '4K短间隔读写(MB/s)',
};

test['test_iorw_3'] = {
    'labels': ['READ 10min', 'WRITE 10min'],
    'title' : 'SEQ长间隔读写(MB/s)',
};

test['test_iorw_4'] = {
    'labels': ['READ 10min', 'WRITE 10min'],
    'title' : '4K长间隔读写(MB/s)',
};

// HL(Q128T10)
test['test_hl_1'] = {
    'labels': ['READ 5s', 'WRITE 5s'],
    'title' : 'SEQ短间隔高并发多任务读写(MB/s)',
};

test['test_hl_2'] = {
    'labels': ['READ 5s', 'WRITE 5s'],
    'title' : '4K短间隔高并发多任务读写(MB/s)',
};

test['test_hl_3'] = {
    'labels': ['READ 10min', 'WRITE 10min'],
    'title' : 'SEQ长间隔高并发多任务读写(MB/s)',
};

test['test_hl_4'] = {
    'labels': ['READ 10min', 'WRITE 10min'],
    'title' : '4K长间隔高并发多任务读写(MB/s)',
};



var data = {};
data['hw'] = {
    'label': '华为',
    'color': '179,181,198',
    'test_io_1_data' : [158, 177, 159, 32, 197],
    'test_io_2_data' : [6.309, 5.627, 6.270, 13.869, 9.302],
    'test_io_3_data' : [51.153, 18.896, 24.480, 59.311, 48.728],
    'test_io_4_data' : [0.077, 0.694, 9.968, 72.103, 52.544],
    'test_io_5_data' : [12182, 180660, 68342, 27746],
    'test_io_6_data' : [16781, 92536, 29659, 20166],
    'test_io_7_data' : [21899, 180300, 43659, 23502],
    'test_io_8_data' : [84, 1.4, 4.2, 20.1],
    'test_io_9_data' : [65.3, 146.5, 169.4, 482.2, 74.9, 76.7, 80.7, 32.6, 11.2, 10.6],
    'test_io_10_data' : [4138, 5599],
    'test_io_11_data' : [0.89, 1.44, 2.92],
    'test_io_12_data' : [309.7, 789],
    'test_io_13_data' : [80.7, 91.2, 80.7, 91.2, 86.0],
    'test_iorw_1_data' : [417.5, 36.07],
    'test_iorw_2_data' : [7.561, 5.42],
    'test_iorw_3_data' : [407.7, 42.36],
    'test_iorw_4_data' : [7.546, 5.694],
    'test_hl_1_data' : [528.1, 297.3],
    'test_hl_2_data' : [262.4, 136.7],
    'test_hl_3_data' : [528.7, 308.1],
    'test_hl_4_data' : [260.2, 137.6],
    /*
    'test_summary_3_data' : [80.7, 91.2, 80.7, 91.2, 86.0],
    'test_summary_4_data' : [80.7, 91.2, 80.7, 91.2, 86.0],
    */
};

data['hp'] = {
    'label': '惠普',
    'color': '255,99,132',
    'test_io_1_data' : [3234, 2684, 1536, 387, 548],
    'test_io_2_data' : [0.309, 0.372, 0.650, 2.581, 1.822],
    'test_io_3_data' : [0.997, 1.435, 41.128, 4.912, 4.468],
    'test_io_4_data' : [1.580, 10.487, 96.058, 387.423, 278.398],
    'test_io_5_data' : [11304, 174430, 66528, 29937],
    'test_io_6_data' : [16185, 89346, 28555, 20273],
    'test_io_7_data' : [19997, 166630, 41912, 24736],
    'test_io_8_data' : [98.2, 1.4, 4.4, 17.5],
    'test_io_9_data' : [61.6, 140.1, 125.3, 384.2, 6.0, 74.4, 76.1, 29.9, 10.1, 10.0],
    'test_io_10_data' : [4642, 4513],
    'test_io_11_data' : [0.83, 1.54, 2.79],
    'test_io_12_data' : [313.9, 973],
    'test_io_13_data' : [80.7, 91.2, 80.7, 91.2, 86.0],
    'test_iorw_1_data' : [587, 219.8],
    'test_iorw_2_data' : [8.873, 7.275],
    'test_iorw_3_data' : [610.8, 240.4],
    'test_iorw_4_data' : [8.779, 7.235],
    'test_hl_1_data' : [748.6, 390.3],
    'test_hl_2_data' : [192.3, 89.22],
    'test_hl_3_data' : [745.9, 581.9],
    'test_hl_4_data' : [175.3, 83.7],
};

data['lx'] = {
    'label': '联想',
    'color': '75,192,192',
    'test_io_1_data' : [2351, 4446, 3781, 650, 1063],
    'test_io_2_data' : [0.425, 0.224, 0.264, 1.536, 0.940],
    'test_io_3_data' : [5.185, 3.342, 1.914, 12.405, 9.760],
    'test_io_4_data' : [1.148, 17.369, 236.323, 640.630, 539.437],
    'test_io_5_data' : [13080, 185450, 68022, 30557],
    'test_io_6_data' : [17809, 99145, 28693, 21822],
    'test_io_7_data' : [21683, 176220, 45380, 25509],
    'test_io_8_data' : [84.0, 1.5, 4.5, 19.2],
    'test_io_9_data' : [62.9, 141.5, 131.0, 396.9, 64.4, 74.5, 77.0, 30.2, 10.1, 10.1],
    'test_io_10_data' : [4536, 4395],
    'test_io_11_data' : [0.84, 1.53, 3.01],
    'test_io_12_data' : [306.6, 791],
    'test_io_13_data' : [79.7, 92.3, 79.7, 92.3, 85.5],
    'test_iorw_1_data' : [616.8, 197.8],
    'test_iorw_2_data' : [23.21, 6.455],
    'test_iorw_3_data' : [652.6, 181.6],
    'test_iorw_4_data' : [22.61, 6.448],
    'test_hl_1_data' : [940.1, 394.2],
    'test_hl_2_data' : [26.57, 88.92],
    'test_hl_3_data' : [1005, 411.1],
    'test_hl_4_data' : [128.1, 92.34],
};

function drawRadarChart(id, label, rgb, data) {
    var ctx = $("#" + id);

    var data = {
	labels: ["运算处理", "IOPS", "IORW", "网络", "应用", "冗余", "压力"],
	datasets: [
            {
		label: label,
		backgroundColor: "rgba(" + rgb + ",0.2)",
		borderColor: "rgba(" + rgb + ",1)",
		pointBackgroundColor: "rgba(" + rgb + ",1)",
		pointBorderColor: "#fff",
		pointHoverBackgroundColor: "#fff",
		pointHoverBorderColor: "rgba(" + rgb + ",1)",
		data: data,
            }
	]
    };

    var myRadarChart = new Chart(ctx, {
	type: 'radar',
	data: data,
	//options: options
	options: {
            scale: {
                reverse: false,
                ticks: {
                    beginAtZero: true,
		    max: 10,
                }
            }
	}
    });
}

function drawLineChart(id) {
    console.log(id);
    var ctx = $("#" + id);

    $('#' + id + '_title').html(test[id]['title']);

    var dataset = new Array();
    $.each(data, function(i, v) {
	var d = {
            type: 'bar',
            label: v['label'] + ' ' + test[id]['title'],
	    backgroundColor: "rgba(" + v['color'] + ",0.2)",
	    borderColor: "rgba(" + v['color'] + ",1)",
            data: v[id + '_data'], 
            borderWidth: 2,
	};
	
	dataset.push(d);
    });

    var chartInstance = new Chart(ctx, {
	type: 'bar',
	data: {
            labels: test[id]['labels'],
            datasets: dataset,
	},
	options: {
            legend: {
		display: true,
            },
            scales: {
		yAxes: [{
                    ticks: {
			beginAtZero:true
                    }
		}]
	    }
	}
    });
}

function initPage() {
    // cpu, iops, iorw, network, app, ha, press
    var d1 = [9.41, 6.3, 7.71, 10, 10, 7.5, 7.87];
    drawRadarChart('hp_summary', '惠普', '255,99,132', d1);
    var d1 = [9.66, 0.93, 4.95, 10, 9.3, 7.5, 8.02];
    drawRadarChart('hw_summary', '华为', '179,181,198', d1);
    var d1 = [10, 9.48, 9.95, 10, 9.77, 7.5, 7.11];
    drawRadarChart('lx_summary', '联想', '75,192,192', d1);

    //
    drawLineChart('test_io_1');
    drawLineChart('test_io_2');
    drawLineChart('test_io_3');
    drawLineChart('test_io_4');

    drawLineChart('test_io_5');
    drawLineChart('test_io_6');
    drawLineChart('test_io_7');
    drawLineChart('test_io_8');

    drawLineChart('test_io_9');
    drawLineChart('test_io_10');

    drawLineChart('test_io_11');
    drawLineChart('test_io_12');

    drawLineChart('test_io_13');

    drawLineChart('test_iorw_1');
    drawLineChart('test_iorw_2');
    drawLineChart('test_iorw_3');
    drawLineChart('test_iorw_4');

    drawLineChart('test_hl_1');
    drawLineChart('test_hl_2');
    drawLineChart('test_hl_3');
    drawLineChart('test_hl_4');


}
